package com.company.example.interceptor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by ywl on 2016/12/12.
 */
public class MyInvocationInterfaceHandler<T> implements InvocationHandler{
    //目标对象
    private Class<?> target;

    public MyInvocationInterfaceHandler(Class<?> target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("---------------before----------------");
//        Object result = method.invoke(target, args);
        System.out.println("---------------after----------------");
        return proxy;
    }

    public T getProxy() {
        return (T) Proxy.newProxyInstance(target.getClassLoader(), new Class[]{target}, this);
    }
}
